$(function(){
  $(".form-horizontal").bootstrapValidator({
    feedbackIcons: {
        valid: 'glyphicon glyphicon-ok',
        invalid: 'glyphicon glyphicon-remove',
        validating: 'glyphicon glyphicon-refresh'
    },
    fields:{
      //配置用户名
     username: {
      validators: {
        //不能为空
        notEmpty: {
          message: '用户名不能为空'
        },
        //长度校验
        stringLength: {
          min: 2,
          max: 12,
          message: '用户名长度必须在6到12之间'
        },
        //正则校验
        regexp: {
          regexp: /^[a-zA-Z0-9_\.]+$/,
          message: '用户名由数字字母下划线和.组成'
        },
        callback: {
          message: '用户名不存在'
        }
      }
    },
    password: {
      validators: {
        //不能为空
        notEmpty: {
          message: '密码不能为空'
        },
        //长度校验
        stringLength: {
          min: 6,
          max: 12,
          message: '用户名长度必须在6到12之间'
        },
        callback: {
          message: '密码错误'
        }
      }
    },
  }

  });

  $(".form-horizontal").on('success.form.bv', function (e) {
    e.preventDefault();
    //使用ajax提交逻辑
    $.ajax({
      url: '/employee/employeeLogin',
      type: 'post',
      data: $('form').serialize(),
      success:function(info){
        if(info.success){
          
          location.href = "index.html";
        }
        if(info.error === 1000){
          $(".form-horizontal")
          .data('bootstrapValidator')
          .updateStatus('username', 'INVALID', 'callback');
        }
        if(info.error === 1001){
          $(".form-horizontal")
          .data('bootstrapValidator')
          .updateStatus('password', 'INVALID', 'callback');
        }
      }
    })
});

$("[type = reset]").on("click",function(){
          $(".form-horizontal")
          .data('bootstrapValidator')
          .resetForm(true);
})

})